/****************************************************************************
 * Chariott - Continuous Integration Testing Tool
 * Zaid Mohsin
 * The University of York
 * 2012/2013
 * MSc in Information Technology
 * All rights reserved.
 ****************************************************************************/
package chariott.testing;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * a class that encapsulates more than one JUnit test case to be run in sequence
 * 
 * @author Zaid
 * 
 */
public class TestSequence implements RunItem {

	ArrayList<TestCase> myCases;

	public TestSequence(ArrayList<TestCase> myCases) {
		this.myCases = myCases;
	}

	public TestSequence() {
		myCases = new ArrayList<TestCase>();
	}

	/**
	 * returns the collective weight of all TestCases under that sequence
	 * 
	 */
	@Override
	public double getWeight() {
		double weight = 0;
		for (TestCase myCase : myCases)
			weight = weight + myCase.getWeight();

		return weight;
	}

	@Override
	public String getName() {
		StringBuilder sb = new StringBuilder();
		Iterator<TestCase> myIt = myCases.iterator();
		while (myIt.hasNext()) {
			sb.append(myIt.next().getName());
			if (myIt.hasNext())
				sb.append(",");
		}

		return sb.toString();
	}

	public String toString() {
		return ("Test Sequence with Test Cases: " + getName());
	}

	public void addCase(TestCase t) {
		myCases.add(t);
	}

	public void remove(TestCase t) {
		myCases.remove(t);
	}

	public ArrayList<TestCase> getTestCases() {
		return myCases;
	}
}
